package com.me.kafka.config;

import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.TopicBuilder;

/**
 * kafka 配置类
 * @author zyt
 */
@Configuration
public class KafkaConfig {

    /**
     * 如果要修改分区数，只需要重启项目即可。
     * 值得注意的是，分区数和副本只能调大不能调小
     * @return
     */
    @Bean
    public NewTopic initTopic1(){
        return TopicBuilder.name("test")
                //分区
                .partitions(10)
                //副本
                .replicas(1)
                .build();
    }

    @Bean
    public NewTopic initTopic2(){
        return new NewTopic("kafka-001",4,(short)-1);
    }

    @Bean
    public NewTopic initTopic3(){
        return new NewTopic("kafka-003",4,(short)-1);
    }

    @Bean
    public NewTopic initTopic4(){
        return new NewTopic("kafka-004",4,(short)-1);
    }
}
